<template>
	<view>
		<view class="app-footer" v-if="appFooter">
			<!-- <view class="app-footer-btn"><u-link class="btn-link" href="huanyuanjing://" text="前往App" @click="linkClick"></u-link></view> -->
			<a href="huanyuanjing://" v-if="$isAndroid" class="app-footer-btn-text"><view class="app-footer-btn" @click="openApp">前往App</view></a>
			<view class="app-footer-btn" v-else @click="openApp"><text>前往App</text></view>
		</view>
	</view>
</template>

<script>
	export default {
		name:"app-footer",
		data() {
			return {
				appFooter:false,
				timer:null,
				opening:true,
			};
		},
		created() {
			// console.log(getApp().globalData)
			if (getApp().globalData.channel) {
				this.appFooter = true;
				document.addEventListener("visibilitychange", () => {
					if (this.timer) {
						this.opening = false
						clearTimeout(this.timer)
					}
				}, false);
			}
			// console.log(this.$isAndroid)
		},
		methods:{
			openApp() {
				if (!this.isWeiXinLogin()) {
					if (this.$isAndroid) {
						// let ifr = document.createElement('iframe');
						// ifr.src = "huanyuanjing://";
						// ifr.style.display = 'none';
						// document.body.appendChild(ifr);
						this.timer = setTimeout(() => {  //  未安装的情况
							// this.opening = false
							// document.body.removeChild(ifr);
							// 3秒不跳，可能没安装
							uni.showToast({
								title:'您还未下载，请前往下载',
								icon:'none'
							})
							setTimeout(() => {
								uni.navigateTo({
									url:'/pages/download-app/download-app'
								})
							},1000)
						}, 3000)
					} else {
						// window.location = ""
						this.timer = setTimeout(() => { //  未安装的情况
							this.opening = false
							//  跳转app store
							// window.location = 'https://apps.apple.com/cn/app/idxxxxxxxxxx'
							// 3秒不跳，可能没安装
							uni.navigateTo({
								url:'/pages/download-app/download-app'
							})
						}, 3000);	
					}
				}
			}
		}
	}
</script>

<style lang="less">
	.app-footer{
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 152rpx;
		background: #202227;
		z-index: 999;
		
		.app-footer-btn{
			width: 686rpx;
			height: 88rpx;
			margin: 32rpx auto 0;
			background: linear-gradient(223deg, #A339D8 0%, #6948F2 100%);
			border-radius: 45rpx;
			font-size: 32rpx;
			font-weight: 500;
			color: #FFFFFF;
			text-align: center;
			line-height: 88rpx;
			
			.btn-link{
				text-align: center !important;
				line-height: 88rpx !important;
				display: block !important;
				color: #ffffff !important;
				font-size: 32rpx !important;
			}
			
			
		}
		.app-footer-btn-text{
			color: #ffffff;
			text-decoration: none;
		}
	}
</style>
